#include "OclLapack.h"
#include "../clUtils.h"
#include "clAmdBlas.h"
#include "../AmdConvertEnum.h"
#include <cmath>
#include "../ClMem.h"

using namespace std;

void OclLapack::ssymv(char *uplo, int n, float alpha,
		const cl_ptr a, int lda,
		const cl_ptr x, int incX,
		float beta,
		cl_ptr y, int incY) 
{
	cl_event event;
	{
		Measure m1("1");	
	
		CL_CHECK(clAmdBlasSsymvEx(clAmdBlasColumnMajor, toAmdUplo(uplo), n, alpha,
				a.handle, a.offset, lda,
				x.handle, x.offset, incX,
				beta,
				y.handle, y.offset, incY,
				1, &queue, 0, NULL,
				&event));
	}
	
	ClEvent e(event);
	{
		Measure m1("2");	
		e.wait();
	}
	
	Profiler::addTime("ssymv enqueue-end", e.getEnqueueToEndSec());
	Profiler::addTime("ssymv submit-end", e.getSubmitToEndSec());
	Profiler::addTime("ssymv start-end", e.getEnqueueToEndSec());
}

int OclLapack::ssymv(char *uplo, int *n, float *alpha, float *a, 
		int *lda, float *x, int *incx, float *beta, float *y, int *incy)
{
	size_t sizeY = 1 + (*n - 1) * abs(*incy);
    ClMem<float> memA(queue, (*lda) * (*n), a);
    ClMem<float> memX(queue, 1 + (*n - 1) * abs(*incx), x);
    ClMem<float> memY(queue, sizeY, y);

	ssymv(uplo, *n, *alpha,
		cl_ptr(memA), *lda,
        cl_ptr(memX), *incx, 
		*beta,
        cl_ptr(memY), *incy);

    memY.beginRead(y, 0, sizeY).wait();
	
    return 0;
}